<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>递归函数，回调函数，闭包函数</title>
    <script>
        /*递归函数*/
        //阶乘
        function fn1(n){
            if(n===1){
                return 1;
 
                n-1);
            }
        }
        console.log(fn1(5));
        //斐波那契数列
        function fn2(n){
            if(n===1||n===2){
                return 1;
            }else{
                return fn2(n-1)+fn2(n-2);
            }
        }
        console.log(fn2(5));
        /*回调函数*/
        function fn3(n,cb){
            for (let i = 0; i< n; i++) {
                console.log(i+1);
                cb();
            }
        }
        fn3(5,()=>{
            console.log("回调函数")
        });
        /*闭包函数*/
        function fn4(){
            let num =10;

            return ()=>{
                console.log(++num)
            };
        }
        let res = fn4();
        res();
        res();
        res();
    </script>
</head>
<body>
    
</body>
</html>